home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Applications / Macintosh Tracker 1.20 / source / Server⁄Tracker 4.0 / dump_song.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-02-01  |  4.6 KB  |  202 lines  |  [TEXT/KAHL]

  1. /* dump_song.c */
  2.  
  3. /* $Id: dump_song.c,v 4.1 1994/01/12 16:11:07 espie Exp espie $
  4.  * $Log: dump_song.c,v $
  5.  * Revision 4.1  1994/01/12  16:11:07  espie
  6.  * Last minute changes.
  7.  *
  8.  * Revision 4.0  1994/01/11  17:46:01  espie
  9.  * Use virtual windows.
  10.  *
  11.  * Revision 1.8  1994/01/09  17:36:22  Espie
  12.  * Generalized open.c.
  13.  *
  14.  * Revision 1.7  1994/01/08  03:55:43  Espie
  15.  * No more call to run_in_fg(), use begin_info result instead.
  16.  *
  17.  * Revision 1.6  1994/01/06  22:32:42  Espie
  18.  * Added instrument name as shown per display.c.
  19.  *
  20.  * Revision 1.5  1994/01/05  16:10:49  Espie
  21.  * *** empty log message ***
  22.  *
  23.  * Revision 1.4  1994/01/05  14:54:09  Espie
  24.  * *** empty log message ***
  25.  *
  26.  * Revision 1.3  1994/01/05  13:50:43  Espie
  27.  * Cosmetic change.
  28.  *
  29.  * Revision 1.2  1993/12/28  13:54:44  Espie
  30.  * Use info facility.
  31.  *
  32.  * Revision 1.1  1993/12/26  00:55:53  Espie
  33.  * Initial revision
  34.  *
  35.  * Revision 3.7  1993/11/17  15:31:16  espie
  36.  * *** empty log message ***
  37.  *
  38.  * Revision 3.6  1993/11/11  20:00:03  espie
  39.  * Amiga support.
  40.  *
  41.  * Revision 3.5  1993/04/28  20:13:13  espie
  42.  * Very small bug with volume (Lawrence).
  43.  *
  44.  * Revision 3.4  1993/04/25  14:08:15  espie
  45.  * Added finetune display.
  46.  *
  47.  * Revision 3.3  1993/01/15  14:00:28  espie
  48.  * Added bg/fg test.
  49.  *
  50.  * Revision 3.1  1992/11/19  20:44:47  espie
  51.  * Protracker commands.
  52.  *
  53.  * Revision 3.0  1992/11/18  16:08:05  espie
  54.  * New release.
  55.  */
  56.  
  57. #include "defs.h"
  58.  
  59. #ifdef MALLOC_NOT_IN_STDLIB
  60. #include <malloc.h>
  61. #else
  62. #include <stdlib.h>
  63. #endif
  64. #include <stdio.h>
  65. #include <string.h>
  66. #include <ctype.h>
  67.  
  68. #include "song.h"
  69. #include "extern.h"
  70. #include "channel.h"
  71.  
  72. ID("$Id: dump_song.c,v 4.1 1994/01/12 16:11:07 espie Exp espie $")
  73.  
  74. LOCAL void *handle = 0;
  75. LOCAL char buffer[80];
  76. extern char instname[];
  77.  
  78. /***
  79.  *
  80.  *  dump_block/dump_song:
  81.  *  shows most of the readable info
  82.  *  concerning a module on the screen.
  83.  *
  84.  ***/
  85.  
  86. LOCAL void dump_block(b)
  87. struct block *b;
  88.    {
  89.    int i, j;
  90.  
  91.    for (i = 0; i < BLOCK_LENGTH; i++)
  92.       {
  93.       for (j = 0; j < NUMBER_TRACKS; j++)
  94.          {
  95.          sprintf(buffer,"%8d%5d%2d%4d", b->e[j][i].sample_number,
  96.             b->e[j][i].pitch, b->e[j][i].effect,
  97.             b->e[j][i].parameters);
  98.          infos(handle, buffer);
  99.          }
  100.       info(handle, "");
  101.       }
  102.    }
  103.  
  104. /* make_readable(s):
  105.  * transform s into a really readable string */
  106.  
  107. LOCAL void make_readable(s)
  108. char *s;
  109.    {
  110.    char *t, *orig;
  111.  
  112.    if (!s)
  113.       return;
  114.  
  115.    orig = s;
  116.    t = s;
  117.  
  118.       /* get rid of the st-xx: junk */
  119.    if (strncmp(s, "st-", 3) == 0 || strncmp(s, "ST-", 3) == 0)
  120.       {
  121.       if (isdigit(s[3]) && isdigit(s[4]) && s[5] == ':')
  122.          s += 6;
  123.       }
  124.    while (*s)
  125.       {
  126.       if (isprint(*s))
  127.          *t++ = *s;
  128.       s++;
  129.       }
  130.    *t = '\0';
  131.    while (t != orig && isspace(t[-1]))
  132.       *--t = '\0';
  133.    }
  134.  
  135. void dump_song(song)
  136. struct song *song;
  137.    {
  138.    int i, j;
  139.    int maxlen;
  140.    static char dummy[1];
  141.  
  142.    
  143.    handle = begin_info(song->title);
  144.    if (!handle)
  145.       return;
  146.  
  147.    dummy[0] = '\0';
  148.    maxlen = 0;
  149.    for (i = 1; i < NUMBER_SAMPLES; i++)
  150.       {
  151.       if (!song->samples[i].name)
  152.          song->samples[i].name = dummy;
  153.       make_readable(song->samples[i].name);
  154.       if (maxlen < strlen(song->samples[i].name))
  155.          maxlen = strlen(song->samples[i].name);
  156.       }
  157.    for (i = 1; i < NUMBER_SAMPLES; i++)
  158.       {
  159.       if (song->samples[i].start || strlen(song->samples[i].name) > 2)
  160.          {
  161.          char s[3];
  162.          
  163.          s[0] = instname[i];
  164.          s[1] = ' ';
  165.          s[2] = 0;
  166.          infos(handle, s);
  167.          infos(handle, song->samples[i].name);
  168.          for (j = strlen(song->samples[i].name); j < maxlen + 2; j++)
  169.             infos(handle, " ");
  170.          if (song->samples[i].start)
  171.             {
  172.             sprintf(buffer, "%5d", song->samples[i].length);
  173.             infos(handle, buffer);
  174.             if (song->samples[i].rp_length > 2)
  175.                {
  176.                sprintf(buffer, "(%5d %5d)", 
  177.                   song->samples[i].rp_offset, 
  178.                   song->samples[i].rp_length);
  179.                infos(handle, buffer);
  180.                }
  181.             else
  182.                infos(handle, "             ");
  183.             if (song->samples[i].volume != MAX_VOLUME)
  184.                {
  185.                sprintf(buffer, "%3d", song->samples[i].volume);
  186.                infos(handle, buffer);
  187.                }
  188.             else 
  189.                infos(handle, "   ");
  190.             if (song->samples[i].finetune)
  191.                {
  192.                sprintf(buffer, "%3d", song->samples[i].finetune);
  193.                infos(handle, buffer);
  194.                }
  195.             }
  196.          info(handle, "");
  197.          }
  198.       }
  199.    end_info(handle);
  200.    handle = 0;
  201.    }
  202.